﻿using Project.Frame.Net.Application.Ex;
using Project.Frame.Net.Application.LogService;
using Project.Frame.Net.Application.Models.Entity;
using Project.Frame.Net.Application.Models.Response;
using Project.Frame.Net.Application.Repository;
using Project.Yan.Net.BLL.DTOs;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Project.Frame.Net.Application.UserApplication
{
    public class UserService : IUserService
    {
        private readonly IUserRepository _userRepository;
        private readonly ILoggerService _loggerService;

        public UserService(IUserRepository userRepository, ILoggerService loggerService)
        {
            _userRepository = userRepository;
            _loggerService = loggerService;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="email"></param>
        /// <returns></returns>
        public async Task<UserUserInfoModel_Respose?> GetUserByUserIEmail(string email)
        {
           var result= await _userRepository.GetUserByUserIEmail(email);
            if (result == null)
            {
                //输出异常
                throw new ServiceException(CodeEnums.其他, "用户信息不存在");
            }
            return new UserUserInfoModel_Respose() { Email=result.Email, Id=result.Id, Username=result.Username};
        }

        public async Task<bool> LogInfoTest(string testRequest)
        {
            _loggerService.LogInformation(testRequest);
            return true;
        }
    }
}
